#ifndef CONERENDERER_H
#define CONERENDERER_H

#include <qopengl.h>

#include <QVector3D>
#include <QVector>

#include <qrender/renderer.h>

class QOpenGLShaderProgram;
class QOpenGLVertexArrayObject;
class QOpenGLBuffer;

class ConeRenderer : public Renderer
{
public:
    ConeRenderer();
    ~ConeRenderer();

    void setPosition(const QVector3D &pos);
    void setShape(const QVector3D &base, const QVector3D &apex, float radius,
                  int slices, const QVector4D &color);
    void setColor(const QVector4D &color);

protected:
    void create() override;
    void render(const CameraInfo &camera) override;
    void release() override;

private:
    /// 生成圆锥顶点坐标
    void generateConeVertices(const QVector3D &base, const QVector3D &apex,
                              float radius, int slices);

private:
    QVector3D pos_{ 0.0, 0.0, 0.0 };
    QVector3D base_{ 0.0, 0.0, 0.0 };
    QVector3D apex_{ 0.0, 20.0, 0.0 };
    float radius_{ 5.0 };
    int slices_{ 30 };
    QVector4D color_{ 0.0, 1.0, 1.0, 1.0 };
    bool data_changed_{ true };

    std::shared_ptr<QOpenGLShaderProgram> program_{ nullptr };
    std::shared_ptr<QOpenGLVertexArrayObject> vao_{ nullptr };
    std::shared_ptr<QOpenGLBuffer> vbo_{ nullptr };

    QVector<QVector3D> vertices_;
    QVector<GLuint> base_indices_;
    QVector<GLuint> side_indices_;
};

#endif // CONERENDERER_H
